import React, {Component, cloneElement} from 'react';
import propTypes from 'prop-types';
import classNames from 'classnames';

class TabContent extends Component {
  static propTypes = {}

  getTabPanes () {
    const {classPrefix, activeIndex, panels} = this.props;
    return panels && panels.map(child => {
      if (!child) return false;
      const order = parseInt(child.props.order, 10);
      const isActive = order === activeIndex;
      return React.cloneElement(child, {
        classPrefix,
        isActive,
        children: child.props.children,
        key: `tabpane-${order}`
      });
    });
  }

  render() {
    const {classPrefix} = this.props;
    const classes = classNames({
      [`${classPrefix}-content`]: true
    });
    return (
      <div className={classes}>
        {this.getTabPanes()}
      </div>
    );
  }

}

export default TabContent;
